<template>
    <div class="mypgbox">
        <div class="jt" :class="{'disabled':pageNum<=1}" @click="goPage(-1)"><el-icon><ArrowLeftBold /></el-icon></div>
        <input type="text" v-model="pageNum" @keyup.enter="goPage(0)" :disabled="finish"/>
        <span>/</span>
        <div class="total">{{Math.ceil((total || 1)/limit)}}</div>
        <div class="jt" :class="{'disabled':finish}" @click="goPage(1)"><el-icon><ArrowRightBold /></el-icon></div>
    </div>
</template>

<script setup>
import {ref,onMounted,watch} from "vue"

const props = defineProps({
    total:'',
    finish:{
        type:Boolean,
        default:false
    },
    limit:{  // 每页显示条数
        type:Number,
        default:10
    },
    page:{  // 当前页
        type:Number,
        default:1
    }
})

const pageNum = ref(1)
const emit = defineEmits(['goPage'])

onMounted(()=>{
    pageNum.value = props.page
})
watch(()=>props.page,(n,o)=>{
    pageNum.value = n
})
const goPage = (num)=>{
    if(num>0 && !props.finish){
        pageNum.value++
        emit('goPage',pageNum.value)
    }else if(num<0 && pageNum.value>1){
        pageNum.value--
        emit('goPage',pageNum.value)
    }else if(num==0){
        emit('goPage',pageNum.value)
    }
}
</script>

<style lang="scss" scoped>
.mypgbox{
    display: flex;
    width: 100%;
    height: 30px;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    .jt{
        display: flex;
        height: 100%;
        width: 20px;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        color: #333;
        &:hover{
            font-weight: bold;
            color: #000;
        }
        &.disabled{
            cursor:not-allowed;
            color: #999;
            &:hover{
                font-weight: bold;
                color: #999;
            }
        }
    }
    input{
        height: 24px;
        border-radius: 2px;
        background-color: #f8f4f4;
        width: 50px;
        border: 0;
        text-align: center;
        margin: 0 0 0 10px;
        font-size: 12px;
    }
    span{
        padding: 0 5px;
        font-size: 12px;
    }
    .total{
        margin: 0 10px 0 0;
        font-size: 12px;
    }
}
</style>